package com.yizhu.zczy.address.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.yizhu.zczy.common.utils.PageUtils;
import com.yizhu.zczy.common.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yizhu.zczy.address.entity.RegionEntity;
import com.yizhu.zczy.address.service.RegionService;
import org.w3c.dom.stylesheets.LinkStyle;


/**
 * 地区表
 *
 * @author guoyz
 * @email guoyz@mail.com
 * @date 2021-06-24 17:05:09
 */
@RestController
@RequestMapping("address/region")
public class RegionController {
    @Autowired
    private RegionService regionService;



    @GetMapping("queryByParentId")
    @ApiOperation("根据父id查询子")
    public R queryByParentId(@RequestParam Integer pid){

        List<RegionEntity> regionEntityList=regionService.queryByParentId(pid);
        return R.ok().setData(regionEntityList);
    }

    @GetMapping("/getAllCity")
    @ApiOperation("获取所有菜单")
    public R getAllCity(){
        List<RegionEntity> regionEntityList=regionService.getAllCity();
        return R.ok().setData(regionEntityList);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("address:region:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = regionService.queryPage(params);
        return R.ok().put("page", page);
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("address:region:info")
    public R info(@PathVariable("id") Integer id){
		RegionEntity region = regionService.getById(id);

        return R.ok().put("region", region);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("address:region:save")
    public R save(@RequestBody RegionEntity region){
		regionService.save(region);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("address:region:update")
    public R update(@RequestBody RegionEntity region){
		regionService.updateById(region);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("address:region:delete")
    public R delete(@RequestBody Integer[] ids){
		regionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
